package mapper;

import model.Course;
import model.Student;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

@Mapper
public interface StudentMapper {
    //分页
    @Select("select * from student limit #{fromIndex},#{pageSize}")
    @Results({
            @Result(column = "id",property = "id",jdbcType= JdbcType.TINYINT),
            @Result(column = "id",property = "scores",javaType = List.class,
            many = @Many(select = "mapper.ScoreMapper.getScoreByStudentId"))
    })
    public List<Student>  selectByPage(@Param("fromIndex") int fromIndex,@Param("pageSize") int pageSize);
    @Select("select * from student")
    public List<Student> findAll();
@Insert("insert into student(name,password,clazz,sex,birthday) values (#{name},#{password},#{clazz},#{sex},#{birthday})")
int insert(Student student);
@Delete("delete from student where id=#{id}")
    void delete(int id);
@Select("select * from student where id=#{id}")
    Student getById(int id);
@Update("update student set name=#{name},password=#{password},clazz=#{clazz},sex=#{sex},birthday=#{birthday} where id=#{id}")
int update(Student student);

    @Select("select * from student where name=#{name} and password=#{password}")
    Student selectByNameAndPassword(@Param("name") String name, @Param("password") String password);
}
